﻿Imports System.Reflection

Namespace Oracle
    Public Class ColumnDefinitionAttributeFactory
        Inherits Kairyu.Extensions.DDL.ColumnDefinitionAttributeFactory

        Public Overrides Function GetCommandText(def As ColumnDefinitionAttribute) As String
            Dim null As String = If(def.IsNullable, "NULL", "NOT NULL")
            Dim t As String = String.Format(def.ColumnType, def.Size)

            Return String.Format("{0} {1}", t, null)
        End Function

        Public Overrides Function GetColumnType(def As ColumnDefinitionAttribute, t As Type) As String
            If t.Equals(GetType(Boolean)) Then
                Return "NCHAR(1)"
            ElseIf t.Equals(GetType(Byte)) Then
                Return "BLOB"
            ElseIf t.Equals(GetType(Char)) Then
                Return "NCHAR(1)"
            ElseIf t.Equals(GetType(DateTime)) Then
                Return "DATE"
            ElseIf t.Equals(GetType(Decimal)) Then
                Return "NUMBER(8)"
            ElseIf t.Equals(GetType(Double)) Then
                Return "NUMBER(8)"
            ElseIf t.Equals(GetType(Int32)) Then
                Return "NUMBER(8)"
            ElseIf t.Equals(GetType(Int64)) Then
                Return "NUMBER(8)"
            ElseIf t.Equals(GetType(Int16)) Then
                Return "NUMBER(8)"
            ElseIf t.Equals(GetType(Single)) Then
                Return "NUMBER(8)"
            ElseIf t.Equals(GetType(String)) Then
                If def.IsStaticLength Then
                    Return "nchar({0})"
                Else
                    Return "NVARCHAR2({0})"
                End If
            Else
                Return "BLOB"
            End If
        End Function
    End Class
End Namespace